import { Injectable } from "@angular/core";
import { BehaviorSubject, Observable } from "rxjs";
import { UserInfo } from "../../interfaces/login-dto";

@Injectable({
    providedIn: 'root'
})
export class UserInfoService {
    // BehaviorSubject 也是一种Subject，它存储着最后发出给obsever的值
    private userinfo$ = new BehaviorSubject<UserInfo>({
        userId: '',
        userName: '',
        userCode: '',
        userType: 0,
        mobilePhone: '',
        sex: 0,
        loginPass: '',
        tenantId: '',
        deptId: '',
        deptName: '',
        tenantName: '',
        hospId: '',
        hospName: '',
        userPhoto: null,
        childrenHospIds: [],
        preUsername: '',
        preTenantId: '',
        preName: '',
        devId: '',
        virtualInnerPhone: '',
        isRDPersonnel: false,
        isAdmin: false,
    })

    setUserModel(model: UserInfo): void {
        this.userinfo$.next(model);
    }

    getUserModel(): Observable<UserInfo> {
        return this.userinfo$.asObservable();
    }
}